package com.easytopit.demo.lianxi.service.impl;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

import com.easytopit.demo.lianxi.dao.UserDao;
import com.easytopit.demo.lianxi.exception.BizException;
import com.easytopit.demo.lianxi.service.UserService;
import com.easytopit.demo.lianxi.user.User;

@Service
public class UserServiceImpl implements UserService {
	
	@Autowired
	private UserDao userDao;
	
	@Override
	public Integer insert(User user) throws BizException {
		if(user.getName() == null) throw new BizException("用户名不能为空");
		if(user.getPasswd() == null) throw new BizException("密码不能为空");
		if(user.getPhone() == null) throw new BizException("电话号码不能为空");
		if(user.getAge() == null) throw new BizException("年龄不能为空");
		return userDao.insert(user);
	}

	@Override
	public boolean amend(Integer id, String name, String passwd, String phone, String age) throws BizException {
		if(id == null)throw new BizException("用户不存在");
		if(name == null)throw new BizException("姓名不能为空");
		if(passwd == null)throw new BizException("密码不能为空");
		if(phone == null)throw new BizException("电话号码不能为空");
		if(age == null)throw new BizException("年龄不能为空");
		userDao.amend(id, name, passwd, phone, age);
		return true;
	}
	
}
